package java类及封装;
public class d {
    public static void main(String[] args) {
        d stu1 = new d("20250805", "张三", "大数据技术");
        stu1.setScore(85);

        d stu2 = new d("20250806", "周八", "软件技术");
        stu2.setScore(92);

        d stu3 = new d("20250807", "吴九", "云计算");
        stu3.setScore(78);
        stu3.setScore(120); // 测试不合法成绩

        // 存储到数组
        d[] students = {stu1, stu2, stu3};

        // 遍历输出并计算平均分
        double total = 0;
        System.out.println("学生信息列表：");
        for (d s : students) {
            s.showInfo();
            total += s.getScore();
        }
        System.out.println("平均分：" + (total / students.length));
    }
    private String studentId;
    private String name;
    private String major;
    private double score;

    // 有参构造方法
    public d(String studentId, String name, String major) {
        this.studentId = studentId;
        this.name = name;
        this.major = major;
    }

    // getter/setter 方法
    public String getStudentId() { return studentId; }
    public void setStudentId(String studentId) { this.studentId = studentId; }

    public String getName() { return name; }
    public void setName(String name) { this.name = name; }

    public String getMajor() { return major; }
    public void setMajor(String major) { this.major = major; }

    public double getScore() { return score; }
    public void setScore(double score) {
        if (score >= 0 && score <= 100) {
            this.score = score;
        } else {
            System.out.println("成绩不合法（必须0-100分）");
        }
    }

    // 显示信息
    public void showInfo() {
        System.out.println("学号：" + studentId + "，姓名：" + name + "，专业：" + major + "，成绩：" + score + "分");
    }
}